home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-expr.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  5KB  |  181 lines

  1. /* Convert language-specific tree expression to rtl instructions,
  2.    for GNU compiler.  Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include "tree.h"
  24. #include "flags.h"
  25. #include "expr.h"
  26. #include "cplus-tree.h"
  27. #include "assert.h"
  28.  
  29. rtx
  30. cplus_expand_expr (exp, target, tmode, modifier)
  31.      tree exp;
  32.      rtx target;
  33.      enum machine_mode tmode;
  34.      enum expand_modifier modifier;
  35. {
  36.   register rtx op0, op1, temp;
  37.   tree type = TREE_TYPE (exp);
  38.   register enum machine_mode mode = TYPE_MODE (type);
  39.   register enum tree_code code = TREE_CODE (exp);
  40.   rtx original_target = target;
  41.   int ignore = target == const0_rtx;
  42.  
  43.   if (ignore) target = 0, original_target = 0;
  44.  
  45.   /* No sense saving up arithmetic to be done
  46.      if it's all in the wrong mode to form part of an address.
  47.      And force_operand won't know whether to sign-extend or zero-extend.  */
  48.  
  49.   if (mode != Pmode && modifier == EXPAND_SUM)
  50.     modifier = EXPAND_NORMAL;
  51.  
  52.   switch (code)
  53.     {
  54.     case CPLUS_NEW_EXPR:
  55.       {
  56.     /* Something needs to be initialized, but we didn't know
  57.        where that thing was when building the tree.  For example,
  58.        it could be the return value of a function, or a parameter
  59.        to a function which lays down in the stack, or a temporary
  60.        variable which must be passed by reference .
  61.  
  62.        Cleanups are handled in a language-specific way: they
  63.        might be run by the called function (true in GNU C++
  64.        for parameters with cleanups), or they might be
  65.        run by the caller, after the call (true in GNU C++
  66.        for other cleanup needs).  */
  67.  
  68.     tree func = TREE_OPERAND (exp, 0);
  69.     tree args = TREE_OPERAND (exp, 1);
  70.     tree type = TREE_TYPE (exp), slot;
  71.     tree fn_type = TREE_TYPE (TREE_TYPE (func));
  72.     tree return_type = TREE_TYPE (fn_type);
  73.     rtx call_target, return_target;
  74.  
  75.     /* The expression `init' wants to initialize what
  76.        `target' represents.  SLOT holds the slot for TARGET.  */
  77.     slot = TREE_OPERAND (exp, 2);
  78.  
  79.     if (target == 0)
  80.       {
  81.         /* Should always be called with a target in BLKmode case.  */
  82.         assert (mode != BLKmode);
  83.         assert (DECL_RTL (slot) != 0);
  84.  
  85.         target = gen_reg_rtx (mode);
  86.       }
  87.  
  88.     /* The target the initializer will initialize (CALL_TARGET)
  89.        must now be directed to initialize the target we are
  90.        supposed to initialize (TARGET).  The semantics for
  91.        choosing what CALL_TARGET is is language-specific,
  92.        as is building the call which will perform the
  93.        initialization.  It is left here to show the choices that
  94.        exist for C++.  */
  95.        
  96.     if (TREE_CODE (func) == ADDR_EXPR
  97.         && TREE_CODE (TREE_OPERAND (func, 0)) == FUNCTION_DECL
  98.         && DECL_CONSTRUCTOR_P (TREE_OPERAND (func, 0)))
  99.       {
  100.         type = TYPE_POINTER_TO (type);
  101.         TREE_VALUE (args) = build1 (ADDR_EXPR, type, slot);
  102.         call_target = 0;
  103.       }
  104.     else if (TREE_CODE (return_type) == REFERENCE_TYPE)
  105.       {
  106.         type = return_type;
  107.         call_target = 0;
  108.       }
  109.     else
  110.       {
  111.         call_target = target;
  112.       }
  113.     return_target = expand_expr (build (CALL_EXPR, type, func, args, 0), call_target, mode, 0);
  114.     if (call_target == 0)
  115.       call_target = return_target;
  116.     else if (call_target != return_target)
  117.       {
  118.         if (GET_MODE (return_target) == BLKmode)
  119.           emit_block_move (call_target, return_target, expr_size (exp),
  120.                    TYPE_ALIGN (type) / BITS_PER_UNIT);
  121.         else
  122.           emit_move_insn (call_target, return_target);
  123.       }
  124.  
  125.     if (TREE_CODE (return_type) == REFERENCE_TYPE)
  126.       {
  127.         tree init;
  128.  
  129.         if (GET_CODE (call_target) == REG
  130.         && REGNO (call_target) < FIRST_PSEUDO_REGISTER)
  131.           abort ();
  132.  
  133.         type = TREE_TYPE (exp);
  134.  
  135.         init = build (RTL_EXPR, return_type, 0, call_target);
  136.         /* We got back a reference to the type we want.  Now intialize
  137.            target with that.  */
  138.         expand_aggr_init (slot, init, 0);
  139.       }
  140.  
  141.     if (DECL_RTL (slot) != target)
  142.       emit_move_insn (DECL_RTL (slot), target);
  143.     return DECL_RTL (slot);
  144.       }
  145.  
  146.     default:
  147.       break;
  148.     }
  149.   abort ();
  150. }
  151.  
  152. /* If DECL had its rtl moved from where callers expect it
  153.    to be, fix it up.  RESULT is the nominal rtl for the RESULT_DECL,
  154.    which may be a pseudo instead of a hard register.  */
  155.  
  156. void
  157. fixup_result_decl (decl, result)
  158.      tree decl;
  159.      rtx result;
  160. {
  161.   if (REG_P (result))
  162.     {
  163.       if (REGNO (result) >= FIRST_PSEUDO_REGISTER)
  164.     {
  165.       rtx real_decl_result;
  166.  
  167. #ifdef FUNCTION_OUTGOING_VALUE
  168.       real_decl_result
  169.         = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl), current_function_decl);
  170. #else
  171.       real_decl_result
  172.         = FUNCTION_VALUE (TREE_TYPE (decl), current_function_decl);
  173. #endif
  174.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  175.       result = real_decl_result;
  176.     }
  177.       emit_move_insn (result, DECL_RTL (decl));
  178.       emit_insn (gen_rtx (USE, VOIDmode, result));
  179.     }
  180. }
  181.